<template>
    <div class="pick-highlight">
        <el-label>开启楼层拾取：</el-label>
        <el-switch v-model="allowPick" />
    </div>
</template>
<script setup lang="ts">
import { onMounted, ref } from "vue";
import { getMyProjectManager } from "@/getMyProjectManager";
const myProjectManager = getMyProjectManager();
// 允许拾取
const allowPick = ref(false)
// 配置项
const options = [
    {
        label: '显示-全部楼层',
        value: 'all',
        view: {
            "position": [
                114.04293905847207,
                38.06645646966434,
                380.9108412987498
            ] as [number, number, number],
            "rotation": [
                349.27484130859375,
                -38.808353424072266,
                -4.081576487110616e-15
            ] as [number, number, number]
        }
    }, {
        label: '显示-综合楼1层',
        value: 'floor_zonghelou_1',
        view: {
            "position": [
                114.04262401378925,
                38.067107395657374,
                356.15311211545867
            ] as [number, number, number],
            "rotation": [
                3.7252120971679688,
                -70.75286865234375,
                0.000008509478902851697
            ] as [number, number, number]
        }
    }, {
        label: '显示-综合楼2层',
        value: 'floor_zonghelou_2',
        view: {
            "position": [
                114.04262401378925,
                38.067107395657374,
                360.15311211545867
            ] as [number, number, number],
            "rotation": [
                3.7252120971679688,
                -70.75286865234375,
                0.000008509478902851697
            ] as [number, number, number]
        }
    }, {
        label: '显示-综合楼3层',
        value: 'floor_zonghelou_3',
        view: {
            "position": [
                114.04262401378925,
                38.067107395657374,
                364.15311211545867
            ] as [number, number, number],
            "rotation": [
                3.7252120971679688,
                -70.75286865234375,
                0.000008509478902851697
            ] as [number, number, number]
        }
    }, {
        label: '显示-综合楼4层',
        value: 'floor_zonghelou_4',
        view: {
            "position": [
                114.04262401378925,
                38.067107395657374,
                368.15311211545867
            ] as [number, number, number],
            "rotation": [
                3.7252120971679688,
                -70.75286865234375,
                0.000008509478902851697
            ] as [number, number, number]
        }
    }, {
        label: '显示-综合楼5层',
        value: 'floor_zonghelou_5',
        view: {
            "position": [
                114.04262401378925,
                38.067107395657374,
                372.15311211545867
            ] as [number, number, number],
            "rotation": [
                3.7252120971679688,
                -70.75286865234375,
                0.000008509478902851697
            ] as [number, number, number]
        }
    }, {
        label: '显示-综合楼6层',
        value: 'floor_zonghelou_6',
        view: {
            "position": [
                114.04262401378925,
                38.067107395657374,
                376.15311211545867
            ] as [number, number, number],
            "rotation": [
                3.7252120971679688,
                -70.75286865234375,
                0.000008509478902851697
            ] as [number, number, number]
        }
    }, {
        label: '显示-综合楼顶层',
        value: 'floor_zonghelou_7',
        view: {
            "position": [
                114.04262401378925,
                38.067107395657374,
                380.15311211545867
            ] as [number, number, number],
            "rotation": [
                3.7252120971679688,
                -70.75286865234375,
                0.000008509478902851697
            ] as [number, number, number]
        }
    }, {
        label: '显示-餐厅1层',
        value: 'floor_canting_1',
        view: {
            "position": [
                114.0429537854672,
                38.06775888994002,
                325.2380013133062
            ] as [number, number, number],
            "rotation": [
                5.646759033203125,
                -61.265716552734375,
                0.00003711675162776373
            ] as [number, number, number]
        }
    }, {
        label: '显示-餐厅2层',
        value: 'floor_canting_2',
        view: {
            "position": [
                114.0429537854672,
                38.06775888994002,
                329.2380013133062
            ] as [number, number, number],
            "rotation": [
                5.646759033203125,
                -61.265716552734375,
                0.00003711675162776373
            ] as [number, number, number]
        }
    }, {
        label: '显示-餐厅3层',
        value: 'floor_canting_3',
        view: {
            "position": [
                114.0429537854672,
                38.06775888994002,
                333.2380013133062
            ] as [number, number, number],
            "rotation": [
                5.646759033203125,
                -61.265716552734375,
                0.00003711675162776373
            ] as [number, number, number]
        }
    }
]
myProjectManager.viewerCreatedEvent.don((viewer) => {
    // 鼠标点击事件监听
    viewer.clickEvent.don((e) => {
        // 是否允许拾取
        if (!allowPick.value) return
        // pick事件发送
        viewer.pick(e.screenPosition as [number, number], 'clickPick', true).then(res => {
            // @ts-ignore
            if (res && res.childPickedInfo && res.childPickedInfo.uePickResult && res.childPickedInfo.uePickResult.parentInfo) {
                // @ts-ignore
                const parentInfo = res.childPickedInfo.uePickResult.parentInfo
                if (Array.isArray(parentInfo) && parentInfo.length > 0) {
                    const tags = parentInfo[0].actorTags
                    // 判断是否拾取到楼层相关内容通过floor
                    if (Array.isArray(tags) && tags.length > 0 && tags[0].includes("floor")) {
                        // 高亮楼层
                        const item = options.find(item => item.value == tags[0])
                        if (!item) return
                        if (item.label.includes("综合楼")) {
                            // 先关闭所有楼层
                            myProjectManager.buildingCollection.toggleFloor('综合楼', false).then(res => {
                                myProjectManager.buildingCollection.setFloorVisible(item.value, item.view)
                            })
                        }
                        if (item.label.includes("餐厅")) {
                            // 先关闭所有楼层
                            myProjectManager.buildingCollection.toggleFloor('餐厅', false).then(res => {
                                myProjectManager.buildingCollection.setFloorVisible(item.value, item.view)
                            })
                        }
                    }
                }
            }
        })
    })
})
</script>
<style scoped>
.pick-highlight {
    color: #fff
}
</style>